﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Library.WebControls {
	public class SpItemCollection : IList<SpListItem>, IList {
		public SpItemCollection() {
			_items = new List<SpListItem>();
		}

		private readonly List<SpListItem> _items;
		public IEnumerator<SpListItem> GetEnumerator() {
			return _items.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}

		public void Add(SpListItem item) {
			_items.Add(item);
		}

		public int Add(object value) {
			Add((SpListItem)value);
			return Count;
		}

		public bool Contains(object value) {
			return Contains((SpListItem)value);
		}

		public void Clear() {
			_items.Clear();
		}

		public int IndexOf(object value) {
			return IndexOf((SpListItem)value);
		}

		public void Insert(int index, object value) {
			_items.Insert(index, (SpListItem)value);
		}

		public void Remove(object value) {
			_items.Remove((SpListItem)value);
		}

		public bool Contains(SpListItem item) {
			return _items.Contains(item);
		}

		public void CopyTo(SpListItem[] array, int arrayIndex) {
			_items.CopyTo(array, arrayIndex);
		}

		public bool Remove(SpListItem item) {
			return _items.Remove(item);
		}

		public void CopyTo(Array array, int index) {
			CopyTo((SpListItem[])array, index);
		}

		public int Count {
			get { return _items.Count; }
		}

		public object SyncRoot {
			get { return this; }
		}

		public bool IsSynchronized {
			get { return false; }
		}

		public bool IsReadOnly {
			get { return false; }
		}

		public bool IsFixedSize {
			get { return false; }
		}

		public int IndexOf(SpListItem item) {
			return _items.IndexOf(item);
		}

		public void Insert(int index, SpListItem item) {
			_items.Insert(index, item);
		}

		public void RemoveAt(int index) {
			_items.RemoveAt(index);

		}

		object IList.this[int index] {
			get { return this[index]; }
			set { this[index] = (SpListItem)value; }
		}

		public SpListItem this[int index] {
			get { return _items[index]; }
			set { _items[index] = value; }
		}
	}
}
